//
//  HEEduHeadVideoCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/18.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEEduHeadVideoCell.h"

@interface HEEduHeadVideoCell ()

@property (nonatomic, strong) UIImageView *coverView; 
@property (nonatomic, strong) UIButton *playBtn;
@property (nonatomic, strong) HEVideoListModel *item;

@end

@implementation HEEduHeadVideoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI {

    _coverView = [UIImageView new];
    _coverView.contentMode = UIViewContentModeScaleAspectFill;
    _coverView.clipsToBounds = YES;
    _coverView.userInteractionEnabled = YES;
    _coverView.backgroundColor = UIColor.orangeColor;
    _coverView.tag = 100;
    [self.contentView addSubview:_coverView];
    
    [_coverView addSubview:self.playBtn];
 
  
    [_coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(0);
        make.right.equalTo(self.contentView).offset(-0);
        make.height.offset(200);
        make.bottom.equalTo(self.contentView);
    }];
    
    [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_coverView);
        make.centerY.equalTo(_coverView);
        make.width.offset(44);
        make.height.offset(44);
    }]; 
}

- (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexPath {
    self.delegate = self.proxyVC;
    
    self.indexPath = indexPath;
    
    HEVideoListModel *item = (HEVideoListModel *)model;
    
    self.item = item;
    [_coverView sd_setImageWithURL:[NSURL URLWithString:item.video_icon] placeholderImage:IMAGE_NAMED(@"noImage")];
}

- (void)playClick {
    if ([self.delegate respondsToSelector:@selector(headCellPlayTheVideoAtIndexPath:model:)]) {
        [self.delegate headCellPlayTheVideoAtIndexPath:self.indexPath model: _item];
    }
}

#pragma mark - getter

- (UIButton *)playBtn {
    if (!_playBtn) {
        _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
        [_playBtn addTarget:self action:@selector(playClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _playBtn;
}

@end
